﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>API</title>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../bootstrap/css/pub.css" rel="stylesheet" />
    <script src="../bootstrap/js/jquery.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
        <script src="bootstrap/js/html5shiv.min.js"></script>
        <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
    <script src="../config.js"></script>
    <script src="../bootstrap/js/Common.js"></script>
    <script src="../bootstrap/js/controls.js"></script>
    <script src="../bootstrap/js/bootstrap-paginator.js"></script>
    <script type="text/javascript">
        $(function () {
            init(1);
        });
        function init(pgindex)
        { //菜单
            var menus = [
                { name: "新增", action: "openAddWin()", css: "btn-primary" },
                { name: "编辑", action: "openEditWin()", css: "btn-primary" },
                { name: "删除", action: "openDelWin()", css: "btn-primary" }
            ];

            $(".menu-container").menu({ items: menus });
            //列表
            var columns = [
                { name: "编号", field: "triggerRuleId" }, { name: "名称", field: "name" },
                {
                    name: "自动解除报警设置", field: "autoReset",
                    formatter: function (value) {
                        if (value == true) {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                },
                {
                    name: "趋势锁定设置", field: "trendLock",
                    formatter: function (value) {
                        if (value == true) {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                },
                {
                    name: "锁定报警信号设置", field: "lockAlarm",
                    formatter: function (value) {
                        if (value == true) {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                },
                {
                    name: "操作", field: "id", title: '操作',
                    formatter: function (value, dataRow) {
                        return '<a href="javascript:void(0);" onclick="ShowTriggers(\'' + value + '\',\'' + dataRow.name + '\')" class="btn btn-sm btn-info" ><i class="fa fa-trash-o"></i>查看触发器列表</a>';
                    }
                }
            ];
            //分页
            var param = { pagesize: pagesize, pageindex: pgindex };
            $("#tab").datagrid({ columns: columns, dblclick: openEditWin }).loadData(host_name + "rule/list", "post", param, function () {
                $.ajax({
                    url: host_name + "rule/count",
                    type: "get",
                    success: function (data) {
                        if (data < 10) {
                            $("#example").hide();
                        }
                        else {
                            $("#example").show();
                            totalcount = Math.ceil(data / pagesize)
                            $('#pageLimit').bootstrapPaginator({
                                currentPage: pgindex,
                                totalPages: totalcount,//总页数
                                numberOfPages: pagenum,//显示页数
                                size: "normal",
                                bootstrapMajorVersion: 3,
                                alignment: "right",
                                itemTexts: function (type, page, current) {
                                    switch (type) {
                                        case "first": return "首页";
                                        case "prev": return "上一页";
                                        case "next": return "下一页";
                                        case "last": return "末页";
                                        case "page": return page;
                                    }//默认显示的是第一页。
                                },
                                onPageClicked: function (event, originalEvent, type, page) {//给每个页眉绑定一个事件，其实就是ajax请求，其中page变量为当前点击的页上的数字。
                                    init(page);
                                }
                            });
                        }
                    }
                });
            });
        }
        //新增报警策略
        function openAddWin() {
            openModalWin("新增报警策略", "triggerruleedit.html?mode=1", refresh, 700, 400);
        }
        //编辑报警策略
        function openEditWin() {
            var row = $("#tab").datagrid().getSelected();
            if (row.length > 0) {
                openModalWin("编辑报警策略", "triggerruleedit.html?mode=2&identity=" + row[0].identity, refresh, 700, 400);
            } else {
                alert("请选择要编辑的数据！");
            }

        }
        //删除报警策略
        function openDelWin() {
            var row = $("#tab").datagrid().getSelected();
            if (row.length > 0) {
                var delUrl = host_name + "rule/delete?identity=" + row[0].identity;
                if (confirm("确定要删除选定的数据吗？")) {
                    $.ajax({
                        url: delUrl,
                        type: "get",
                        success: function (data) {
                            refresh();
                        }
                    });
                }
            }
            else {
                alert("请选择要删除的数据！");
            }
        }
        //查看触发器列表
        function ShowTriggers(val, name) {

            window.open("triggerlist.html?mode=1&identity=" + val + "&ruleName=" + encodeURI(name),"appIframe");
        }

        //刷新
        function refresh() {
            $("#tab").datagrid().refresh();
        }
    </script>
</head>
<body>
    <div class="container-fluid">
        <div class="row" style="margin-bottom:10px">
            <div class="col-md-2">
                <h4>报警策略</h4>
            </div>
            <div class="col-md-10">
                <div class="menu-container pull-right">

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 table-responsive">
                <table id="tab" class="table table-bordered table-hover"></table>
            </div>
        </div>
        <div class="row" style="margin-right: 10px;">
            <div id="example" style="text-align: right">
                <ul id="pageLimit"></ul>
            </div>
        </div>
    </div>
</body>
</html>